<template>
    <div class="paid">
    <div>
      <div class="top">
        <div class="left">
          <h1>(总共{{sum_account}}份)</h1>
        </div>
        <div class="right">
          <span><i>¥{{sum_price.toFixed(2)}}</i></span>
        </div>
      </div>
      <div>
        <table>
          <thead>
            <tr>
              <th></th>
              <th>商品名称</th>
              <th>商品单价</th>
              <th>数量</th>
              <th>价格</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(ele, index) in detail_lists" :key="index">
              <td>
                <img :src="'http://localhost:3000'+ele.imgUrl"  alt="">
              </td>
              <td>
                {{ele.name}}
              </td>
              <td>
                ¥{{ele.price.toFixed(2)}}/份
              </td>
              <td class="number">
                <input readonly :value="ele.account" type="text">
              </td>
              <td>
                ¥{{(ele.price*ele.account).toFixed(2)}}
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
    
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name:"Detali",
  created() {
    const {time,user_id} = this.$route.query
    this.$store.dispatch('OrderDetail',{time,user_id})
  },
  computed: {
    ...mapState({
      detail_lists:(state)=>{
        return state.food.detail
      }
    }),
    sum_price(){
      return this.detail_lists.reduce((pre,ele)=>{
        return pre+= ele.price*ele.account
    },0)
    },
    sum_account(){
      return this.detail_lists.reduce((pre,ele)=>{
          return pre+=ele.account
      },0)
    }
  },
}
</script>

<style lang="less" scoped>
.paid {
  padding: 20px;
  width: 1000px;
  height: 100%;
  background-color: #fff;
  border: 1px solid #fff;
  border-radius: 15px;
  margin: 0 auto;
  .top {
    display: flex;
    height: 60px;
    line-height: 40px;
    justify-content: space-between;
    border-bottom: 1px solid #e6e6e6;
    .right {
      span {
        margin-right: 10px;
        color: #ff5000;
        font-size: 24px;
        i {
          margin-right: 5px;
          font-size: 18px;
        }
      }
      button {
        width: 90px;
        height: 40px;
        background-color: #ff5000;
        color: #fff;
        border: 1px solid #fff;
        border-radius: 15px;
        cursor: pointer;
        font-size: 16px;
      }
    }
  }
  table {
    margin-left: 10px;
    width: 1000px;
    font-size: 16px;
    img {
      width: 40px;
      height: 40px;
    }
    thead {
      th {
        text-align: center;
        width: 20%;
      }
    }
    tbody {
      tr {
        td {
          padding: 10px;
          text-align: center;
          width: 20%;
        }
      }
    }
    .number {
      padding: 19px 80px;
      width: 20%;
      box-sizing: border-box;
      display: flex;
      // background-color: pink;
      ::v-deep button {
        margin-right: 2px;
        width: 20px;
        border-radius: 5px;
        border: 1px solid rgba(198, 218, 194, 0.267);
        cursor: pointer;
      }
      .default-button-style {
        background: #fff;
        border-color: #cbcbcd;
      }
      .default-button-style:hover {
        background: #ecf5ff;
        border: 1px solid #409eff;
      }
      input {
        text-align: center;
        width: 50px;
        margin-right: 2px;
        border-radius: 5px;
        border: 1px solid rgba(198, 218, 194, 0.267);
      }
    }
  }
}
</style>